/*
文件编码：UTF8
题目：HDOJ2602
类型：01背包
编写人：wei
编写时间：2016-5-18
*/

#include<iostream>
#include<algorithm>
#include<cstring>

using namespace std;

int T,N,V;
int max_val[1001];
int val[1001];
int weight[1001];

int main()
{
	cin >> T;
	for (int i = 0; i < T; ++i)
	{
		memset(val,0,sizeof(int)*1001);
		memset(max_val,0,sizeof(int)*1001);
		memset(weight,0,sizeof(int)*1001);

		cin >> N >> V;
		for (int j = 1; j <= N; ++j)
		{
			cin >> val[j];
			//cout<<val[j];
		}
		for (int j = 1; j <= N; ++j)
		{
			cin >> weight[j];
			//cout<<val[j];
		}
		
		for (int j = 1; j <= N; ++j)
		{
			for (int k = V; k>=weight[j] ; k--)
			{
				if(max_val[k] > max_val[k-weight[j]]+val[j])
					max_val[k]=max_val[k];
				else
					max_val[k]=max_val[k-weight[j]]+val[j];
			}
		}

		cout << max_val[V] << endl;
	}
	return 0;
}
